import { series, parallel, type TaskFunctionCallback } from "gulp";

import { Print } from "../utils/index";
import { SassDosc } from "../compile/dosc";
import { SassCompile } from "../compile/sass";
import { SASS_DIR, OUT_CSS_DIR, OUT_DOCS_DIR } from "../../config";

export function sassCompileTask(next: TaskFunctionCallback) {
  Print.info("SASS编译开始...");
  const compile = new SassCompile(SASS_DIR);
  const stream = compile.exec(OUT_CSS_DIR);
  Print.info("SASS编译结束...");
  return stream;
}

export function sassDocsTask(next: TaskFunctionCallback) {
  Print.info("SASS文档生成开始...");
  try {
    (new SassDosc(SASS_DIR)).generate(OUT_DOCS_DIR);
  } catch (e) {
    Print.error("Docs文档生成错误");
    Print.error(e, { inverse: true });
  }
  Print.info("SASS编译结束...");
  next();
}

export const sassTask = series(
  sassCompileTask, parallel(sassDocsTask)
);
